package menuBranch;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;


// Project: 

/******************************************************************************
 * <p>
 * File: FullScreenTest.java
 * </p>
 * @author  Tadhg O'Sullivan, rogue
 * @author <a href="mailto:tadhg.osullivan@ucdconnect.ie">tadhg.osullivan@ucdconnect.ie</a>
 * @version 1.0, 2007
 * @created Jan 3, 2007 1:25:36 PM
 * @revised 
 * <p>
 * Description: Tests the SimpleScreenManager
 * </p>
 *****************************************************************************/

public class FullScreenTest extends JFrame implements KeyListener, MouseListener{
	BufferedImage tile;
	tileObject tileArray[][];
	static DisplayMode displayMode;
	static JFrame options;
	JLabel label1, label2, label3;
	
	public static void main(String[] args){
		options = new JFrame();
		
		if(args.length == 3){
			displayMode = new DisplayMode(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), DisplayMode.REFRESH_RATE_UNKNOWN);
		}else{
			displayMode = new DisplayMode(1440, 900, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
		}
		
		options.setLayout(new GridLayout(5,1));
		options.setBackground(Color.BLACK);
		options.setUndecorated(true);
		options.setSize(displayMode.getWidth() / 2,displayMode.getHeight() / 2);
        options.pack();
        Dimension d = options.getSize();
        int x = d.width / 2;
        int y = d.height / 2;
        options.setLocation(displayMode.getWidth() / 2 - x,displayMode.getHeight() / 2 - y);
        options.setResizable(false);
		options.setVisible(true);
		
		FullScreenTest test = new FullScreenTest();
		test.run(displayMode);
		
	}
	
	private static final long DEMO_TIME = 20000;
	
	public void run(DisplayMode displayMode){
		setBackground(Color.blue);
		setForeground(Color.white);
		addKeyListener(this);

		SimlpeScreenManager screen = new SimlpeScreenManager();	
		try {
			screen.setFullScreen(displayMode, this);
			try {
				Thread.sleep(DEMO_TIME);
			} catch (InterruptedException ex) {
				// TODO: handle exception
			}
		} finally{
			screen.restoreScreen();
		}
	}
	
	public void options(){
        
        java.awt.Font font = new java.awt.Font("Serif",Font.BOLD,18);
        Border border = BorderFactory.createLineBorder(Color.RED);
        //Create the first label.
        label1 = new JLabel("OPTIONS",JLabel.CENTER);
        label1.setFont(new Font("Serif",Font.BOLD,24));
        label1.setForeground(Color.WHITE);
        label1.setBorder(border);
        label2 = new JLabel("Return",JLabel.CENTER);
        label2.setFont(font);
        label2.setForeground(Color.WHITE);
        label2.setBorder(border);
        label2.addMouseListener(this);
        label3 = new JLabel("Quit",JLabel.CENTER);
        label3.setFont(font);
        label3.setForeground(Color.WHITE);
        label3.setBorder(border);
        label3.addMouseListener(this);

        //Create tool tips, for the heck of it.
        label2.setToolTipText("Return to game");
        label3.setToolTipText("Exit game");

        //Add the labels.
        options.add(label1);
        options.add(label2);
        options.add(label3);
	}
	
	public void paint(Graphics g){
		// add anti-aliasing
		if(g instanceof Graphics2D) {
			Graphics2D g2 = (Graphics2D)g;
			g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
			drawTiles dt = new drawTiles();
			tileArray = dt.drawMap();
			for(int i=0;i<25;i++){
				for(int j=0;j<40;j++){
					tile=tileArray[i][j].getImage();
					Image scaledImage = tile.getScaledInstance(10*(displayMode.getWidth()/320),10*(displayMode.getHeight()/200), tile.SCALE_FAST);
					g2.drawImage(scaledImage,  j *displayMode.getWidth()/40, i * displayMode.getHeight()/25, null);
				}
			}
		    
		}
		
		
	}

	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		int keyCode = e.getKeyCode();
        String keyText = e.getKeyText(keyCode);
        System.out.println(keyText);
		if(keyText.equalsIgnoreCase("Escape")){
			options.setVisible(true);
		}
		
	}

	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
	if(e.getComponent() == label2){
		options.setVisible(false);
	}
	if(e.getComponent() == label3){
		System.exit(0);
	}
		
	}

	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
}
